package engine.utils
{
	public class DataUtils
	{
		public static function cast(value:String):*
		{
			if(value == "true") 		return true;
			if(value == "false") 		return false;
			if(value == "null")			return null;
			if(!isNaN(Number(value))) 	return Number(value);
			
			return value;
		}
		
		public static function clearWhitespace(value:String):String
		{
			var pattern:RegExp = /[\s\r\n]*/gim;
			return value != null ? value.replace(pattern, "") : "";
		}
		
		public static function isString(value:*):Boolean
		{
			if(!(value is String)) 		return false;
			if(value == "") 			return false;
			if(value == "null")			return false;
			if(value == "undefined")	return false;
			
			return true;
		}
		
		public static function isBoolean(value:*):Boolean
		{
			return value is Boolean ? true : false;
		}
		
		public static function isNumber(value:*):Boolean
		{
			if(!(value is Number)) 	return false;
			if(isNaN(value))		return false;
			
			return true;
		}
		
		public static function toBoolean(value:String):Boolean
		{
			return value == "true" ? true : false;
		}
		
		public static function toNumber(value:String):Number
		{
			return isNaN(Number(value)) ? NaN : Number(value);
		}
		
		public static function toArray(value:String):Array
		{
			value = DataUtils.clearWhitespace(value);
			return value.split(",");
		}
	}
}